/*
    9. Write a program in C to count total number of vowel or consonant in a string. 

    Test Data :
    Input the string : Welcome to w3resource.com

    Expected Output :

    The total number of vowel in the string is : 9 
    The total number of consonant in the string is : 12 
*/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char* getstr(char *str)
{
    char ch;
    char *p = str;
    while((ch = getchar()) != '\n'){
        *p = ch;
        p++;
    }
    *p = '\0';
    return str;
}

int getstrlen(char *str)
{
    int len = 0;
    char *p = str;
    while(*p != '\0'){
        len++;
        p++;
    }
    len++; // '\0'
    return len;
}

void countVC(char *str)
{
    const char v[5] = {'a', 'e', 'i', 'o', 'u'};
    int i;
    int vow = 0, charlen = 0;
    while(*str != '\0'){
        for(i = 0; i < 5; i++){
            if(*str == v[i]){
                vow++;
            }
        }
        if(isalpha(*str)){
            charlen++;
        }
        str++; 
    }
    printf("The total number of vowel in the string is : %d\n", vow);
    printf("The total number of consonant in the string is : %d\n", charlen - vow);  

}

int main(void)
{
    char *str = malloc(1024);
    printf("Input the string : ");
    getstr(str);
    countVC(str);
    return 0;
}